﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SolidWorks.Interop.sldworks;

namespace SolidworksDLL
{
    public partial class UserControl1 : UserControl
    {

        public ModelDoc2 swModel;
        public string cfgName;
        public UserControl1(Dictionary<string, string> ptyDict, ModelDoc2 _swModel,string _cfgName)
        {
            InitializeComponent();
            swModel = _swModel;
            cfgName = _cfgName;
            dataGridView1.Rows.Clear();
            foreach (var item in ptyDict)
            {
                dataGridView1.Rows.Add(new object[] { item.Key,item.Value});
            }

            dataGridView1.ReadOnly = false;

            foreach (DataGridViewColumn item in dataGridView1.Columns)
            {
                if (item.Index == 0)
                {
                    item.ReadOnly = true;
                }
                else
                {
                    item.ReadOnly = false;
                } 
            }



        }

        private void DataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex<0)
            {
                return;
            }

            string name = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
            string value = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();

            if (swModel==null)
            {
                return;
            }

            CustomPryHelp.AddPryByName(swModel,cfgName,name,value);
             
        }
    }
}
